/**
 * @author gao
 * @date 2025/6/12 22:40
 */

public class Solution {
    public int minSubArrayLen(int target, int[] nums) {
        int sum = 0, len = Integer.MAX_VALUE;
        for (int right = 0, left = 0; right < nums.length; right++) {
            sum += nums[right];
            while (sum >= target) {
                len = Math.min(right - left + 1, len);
                sum -= nums[left++];
            }
        }
        //如果数组元素之和小于target，返回0
        return len == Integer.MAX_VALUE ? 0 : len;
    }

    public static void main(String[] args) {
        int target = 7;
        int[] nums = new int[]{2, 3, 1, 2, 4, 3};
        Solution solution = new Solution();
        System.out.println(solution.minSubArrayLen(target, nums));
    }
}